<?php
require_once(dirname(__FILE__) . '/include/config.inc.php');
date_default_timezone_set('PRC');


/*
 自动计算加班费
int $fee   费用标准
int $signInTime   签到时间
int $cfg_jiabanfei 加班每小时奖励

*/
function autoSumFee($fee,$signInTime,$cfg_jiabanfei)
{


    // 计算 费用
    // 获取最后一次签到时间
    $getFee = 0;
    $time_now ='1612616048';
    //计算 施工时间
    $hour_now = date("H", $time_now);
    //加班
    $hour_18 = date("2021-02-06 18:00:00");
    echo $hour_18;
    $fenge_time = strtotime($hour_18);

    //没有 跨天
    if (date("Ymd",$signInTime) == date("Ymd", $signInTime)) {
        // 加班情况
        if ($hour_now < 18) {
            //没有加班
            echo "<br>没有跨时间段<br>";
            $min_count = ($time_now - $signInTime) / 60; //施工分钟数
            $min_fee = $fee/600; //每分钟的数值
            $getFee = ceil($min_count*$min_fee);

        } else {

            echo "<br>跨时间段<br>";
            //加班跨时段
            if ($signInTime < $fenge_time) {
                //正常时段
                //精确到分钟
                echo  "<br>小于18:<br>";
                $min_count = ($fenge_time - $signInTime) / 60; //施工分钟数
                echo  "<br>施工分钟数:$min_count<br>";
                $min_fee = $fee/600; //每分钟的数值
                $getFee = ceil($min_count*$min_fee);
                echo  "<br>$getFee<br>";
                //加班时段
                $hour2 = ($time_now - $fenge_time) / 3600;
                $hour2 = round($hour2,2);
                // 加班时间最多按4个小时算
                //不足4小时的，精确到分钟
                if ($hour2 < 4) {
                    $getFee += ceil(($time_now - $fenge_time) * ($cfg_jiabanfei / 3600));
                } else {
                    $getFee += $cfg_jiabanfei * 4;
                }

            } else {
                echo "nono";
                $hour2 = ($time_now - $fenge_time) / 3600;
                $hour2 = round($hour2,2);
                //echo "当前时间18 " . $hour2 . "<br>";
                if ($hour2 < 4) {
                    $getFee = ceil(($time_now - $signInTime) * ($cfg_jiabanfei / 3600));
                } else {
                    $getFee = $cfg_jiabanfei * 4;
                }
            }


        }

    } else {
        //正常时段

        $hour_18 = date("Y-m-d 18:00:00");
        $fenge_time = strtotime($hour_18)-86400;

        // 第一天从 签到到 18点的时间
        if($fenge_time>$signInTime){
            $min_count = ($time_now - $signInTime) / 60; //施工分钟数
            $min_fee = $fee/600; //每分钟的数值
            $getFee = ceil($min_count*$min_fee);
        }
        // 从晚上18点-第二天 0:00
        $getFee += $cfg_jiabanfei * 4;


    }
    return $getFee;
}

echo autoSumFee(260,1612601488,45);


?>


